# 业务层View：实现登录、注册
import orm


def login():
    path = r'users.json'
    name = input('请输入你的用户名：')
    pwd = input('请输入你的密码：')
    tag = 0
    user_list = orm.read_data(path)
    for user in user_list:
        if name == user['username'] and pwd == user['password']:
            tag = 1
            break
    return tag


def register():
    path = r'users.json'
    name = input('请输入注册用户名：')
    pwd = input('请输入注册密码：')
    user_list = orm.read_data(path)
    new_user = {'username': name, 'password': pwd}      # 定义一个新的字典
    user_list.append(new_user)                      # 添加把这个字典添加到列表中
    orm.write_data(user_list, path)


if __name__ == '__main__':
    # print(assert())  # 登录
    register()      # 注册
